package com.cloud.flowbusdemo.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.cloud.flowbusdemo.R;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @auth: njb
 * @date: 2024/10/11 23:55
 * @desc: 描述
 */
public class ToastView {
    public static void show(Context context, String msg,int duration) {
        Toast toast = new Toast(context);
        //设置Toast显示位置，居中，向 X、Y轴偏移量均为0
        toast.setGravity(Gravity.CENTER, 0, 0);
        //获取自定义视图
        View view = LayoutInflater.from(context).inflate(R.layout.layout_custom_toast, null);
        TextView tvMessage = (TextView) view.findViewById(R.id.toast_tv);
        //设置文本
        tvMessage.setText(msg);
        //设置视图
        toast.setView(view);
        //设置显示时长
        toast.setDuration(duration);
        //显示
        toast.show();
    }

}
